﻿using CGT.OP.App_Start;
using CGT.OP.Common;
using OF.Component.BLL;
using OF.Component.DTO;
using OF.Component.Model;
using OF.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CGT.OP.Controllers
{
    public class OrderController : BaseController
    {
        // GET: Order
        [Authentication(MenuCode = "cgt10101")]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ContentResult GetOrderList()
        {
            ResultData<List<NetworkOrderDto>> rData = new ResultData<List<NetworkOrderDto>>();
            NetworkOrderCondition searchObj = new NetworkOrderCondition();
            searchObj.StartDateTime = "";
            searchObj.EndDateTime = "";
            searchObj.rows = GetPageSize();
            searchObj.page = GetPageIndex();
            int provinceId = EConvert.ToInt(GetParam("provinceid"));
            int cityId = EConvert.ToInt(GetParam("cityid"));
            int masterBizTypeId = EConvert.ToInt(GetParam("masterbiztype"));
            int bizTypeId = EConvert.ToInt(GetParam("biztype"));
            long orderId = EConvert.ToLong(GetParam("orderid"));
            string sDate = GetParam("sDate");
            string eDate = GetParam("eDate");
            if (provinceId > 0)
            {
                searchObj.ProvinceId = provinceId;
            }
            if (cityId > 0)
            {
                searchObj.CityId = cityId;
            }
            if (masterBizTypeId > 0)
            {
                searchObj.MasterBizTypeId = masterBizTypeId;
            }
            if (bizTypeId > 0)
            {
                searchObj.BizTypeId = bizTypeId;
            }
            if (orderId > 0)
            {
                searchObj.OrderID = orderId;
            }
            if (!string.IsNullOrWhiteSpace(sDate))
            {
                searchObj.StartDateTime = sDate;
            }
            if (!string.IsNullOrWhiteSpace(eDate))
            {
                searchObj.EndDateTime = eDate;
            }
            var list = NetworkOrderOperate.SearchList(searchObj);
            rData.data = list.ToList();
            rData.message = searchObj.total.ToString();
            return ReturnResult(rData);
        }

        /// <summary>
        /// 订单详情
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpGet]
        [Authentication(MenuCode = "cgt10101")]
        public ActionResult OrderInfo(long orderId)
        {
            var info = NetworkOrderOperate.GetOrderInfo(orderId);
            if (info==null)
            {
                info = new NetworkOrderDetailDto();
            }
            return View(info);
        }

        /// <summary>
        /// 照片查看
        /// </summary>
        /// <param name="imgUrl"></param>
        /// <returns></returns>
        public ActionResult ImagePreview(string imgUrl)
        {
            @ViewBag.ImgUrl = imgUrl;
            return View();
        }

        /// <summary>
        /// 照片查看
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult OrderAudit(long orderId)
        {
            @ViewBag.OrderId = orderId;
            return View();
        }

        /// <summary>
        /// 订单审核结果
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult OrderAuditResult(long orderId)
        {
            @ViewBag.OrderId = orderId;
            @ViewBag.OrderCreateTime = "";
            NetworkOrderInfo orderObj = NetworkOrderOperate.GetByID(orderId);
            if (orderObj != null)
            {
                @ViewBag.OrderCreateTime = orderObj.CreatedDate.ToString("yyyy-MM-dd HH:mm:ss");
            }
            return View();
        }

        /// <summary>
        /// 获取操作记录
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ContentResult GetOperateRecordByOrderId(long orderId)
        {
            ResultData<List<NetworkOrderAuditDto>> rData = new ResultData<List<NetworkOrderAuditDto>>();
            var list = NetworkOrderAuditOperate.GetListByOrderId(orderId);
            rData.data = list;
            return ReturnResult(rData);
        }

    }
}